############################
# author：码农小易
# blog：https://blog.csdn.net/csdn_xiaoyi
# 回溯法经典问题：迷宫问题
############################

weight = 0
height = 0

def go(labyrinth, x, y, x1, y1, route = [], solutions = []):

    global weight, height
    
    if x == x1 and y == y1:    
        route.append((y, x))                                            #到达终点
        solutions.append((route, len(route)))
        return route[0:-1], solutions

    if x >= weight or y >= height or x < 0 or y < 0:                    #边界检测
        return route, solutions

    if labyrinth[x][y] == 0:
        return route, solutions

    labyrinth[x][y] = 0
    route.append((y, x))

    route, solutions = go(labyrinth, x-1, y, x1, y1, route, solutions)  #向上走
    route, solutions = go(labyrinth, x+1, y, x1, y1, route, solutions)  #向下走
    route, solutions = go(labyrinth, x, y-1, x1, y1, route, solutions)  #向左走
    route, solutions = go(labyrinth, x, y+1, x1, y1, route, solutions)  #向右走

    labyrinth[x][y] = 1                                               
    return route[0:-1], solutions

def main():
    global weight, height
    weight, height = map(int, input('SIZE > ').split())                 #迷宫大小
    labyrinth = [[0 for i in range(weight)] for j in range(height)]     #初始化迷宫边界大小
    print('  ' + ' '.join([str(i) for i in range(weight)]))
    for j in range(height):
        labyrinth[j] = list(map(int, input(str(j)+' ').split()))
    starty, startx = map(int, input('start position > ').split())
    endy, endx = map(int, input('end position > ').split())

    _ , solutions = go(labyrinth, startx, starty, endx, endy)           #开始走迷宫

    if len(solutions) == 0:
        print('no solution.')
    else:
        solutions.sort(key=lambda x:x[1])
        for solution in solutions:
            print(solution)

if __name__ == "__main__":
    main()